<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>JSSpec results</title>
<link rel="stylesheet" type="text/css" href="../JSSpec/JSSpec.css" />

<!-- Scripts for amok -->
<script type="text/javascript" src="../amok/amok.js"></script>

<!-- Scripts for JSSpec -->
<script type="text/javascript" src="../JSSpec/diff_match_patch.js"></script>
<script type="text/javascript" src="../JSSpec/JSSpec.js"></script>

<!-- Scripts for specs -->
<script type="text/javascript" src="../squigle.js"></script>
<script type="text/javascript" src="../svgAdapter.js"></script>

<script type="text/javascript">// <![CDATA[

/**
    As a squigle user
    I want to be able globaly define the adaptor in use
    So that I don't have to pass the adaptor object to many constructors
 */
describe('Scenario 1: User sets the global adaptor', {
	'before_each': function() {

	},
	'Given squigle is available as a namespace': function() {
		value_of(typeof squigle).should_be('object')
	},
	'And value of getAdapter does not equal "testAdapter"': function(){
		value_of(squigle.getAdapter()).should_not_be("testAdapter");
	},
	'When a value is passed to setAdapter then getAdapter will hold the same value': function(){
		squigle.setAdapter("testAdapter");
		value_of(squigle.getAdapter());
	}
});

/**
    As a squigle user
    I want a Size class
    So that I have a uniform interface for storing size values
 */
describe('Scenario 2: User creates a size object and users getters and setter', {
	'before_each': function() {
        size = new squigle.Size(200,300);
	},
	'Given the squigle namespace is available': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And we have an instance of size': function(){
        value_of(typeof size).should_be('object');  
    },
	'When width is called the first value passed to the constructor will be returned': function() {
        value_of(size.width()).should_be(200);
	},
	'When height is called the second value passed to the constructor will be returned': function() {
        value_of(size.height()).should_be(300);
	}
});

/**
    As a squigle user
    I want a Point class
    So that I have a uniform interface for storing point values
 */
describe('Scenario 3: User creates a point object and uses getters and setter', {
	'before_each': function() {
        point = new squigle.Point(20,30);
	},
	'Given the squigle namespace is available': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And we have an instance of size': function(){
        value_of(typeof point).should_be('object');  
    },
	'When getWidth is called the first value passed to the constructor will be returned': function() {
        value_of(point.x()).should_be(20);
	},
	'When getHeight is called the second value passed to the constructor will be returned': function() {
        value_of(point.y()).should_be(30);
	}
});

/**
    As a squigle user
    I want I want to be able to create a canvas
    So that I can draw my vectors on it
 */
describe('Scenario 5: User gets the canvas dom object by calling node', {
	'before_each': function() {
        var sizeMock = amok.mock(squigle.Size);
        sizeMock.should_receive('width').and_return(200);
        sizeMock.should_receive('height').and_return(300);
        
        var adaptorCanvasMock = amok.mock(squigle.svgAdapter.Canvas);
        adaptorCanvasMock.should_receive("node").and_return({});
        adaptorCanvasMock.should_receive("container").and_return({});
        
        squigle.Canvas.prototype._canvasDependancy = adaptorCanvasMock; //Dependancy injection
        canvas = new squigle.Canvas(sizeMock);
	},
	'Given squigle is available as a namespace': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And an instance of canvas is available': function(){
        value_of(typeof canvas).should_be('object');  
    },
	'When node() is called it will return a valid dom object': function() {
        value_of(typeof canvas.node()).should_be("object");
	}
});

describe('Scenario 6: User appends an item to the canvas', {
	'before_each': function() {
        var sizeMock = amok.mock(squigle.Size);
        sizeMock.should_receive('width').and_return(200);
        sizeMock.should_receive('height').and_return(300);
        
        var canvasDomStub = document.createElement("div");
        
        var adaptorCanvasMock = amok.mock(squigle.svgAdapter.Canvas);
        adaptorCanvasMock.should_receive("node").and_return(canvasDomStub);
        adaptorCanvasMock.should_receive("container").and_return({});
        
        squigle.Canvas.prototype._canvasDependancy = adaptorCanvasMock; //Dependancy injection
        canvas = new squigle.Canvas(sizeMock);       
	},
	'Given squigle is available as a namespace': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And an instance of canvas is available': function(){
        value_of(typeof canvas).should_be('object');  
    },
	'When a shape object is passed to append then the objects dom object will be returned': function() {
        rectangleMock = amok.mock(squigle.Rectangle);
        rectangleDomStub = document.createElement("div");
        rectangleMock.should_receive("node").and_return(rectangleDomStub);
        
        value_of( canvas.append(rectangleMock)).should_be(rectangleDomStub);
	}
});

describe('Scenario 7: User removes an item to the canvas', {
	'before_each': function() {
        var sizeMock = amok.mock(squigle.Size);
        sizeMock.should_receive('width').and_return(200);
        sizeMock.should_receive('height').and_return(300);
        
        canvasDomStub = document.createElement("div");
        
        var adaptorCanvasMock = amok.mock(squigle.svgAdapter.Canvas);
        adaptorCanvasMock.should_receive("node").and_return(canvasDomStub);
        adaptorCanvasMock.should_receive("container").and_return({});
        
        rectangleMock = amok.mock(squigle.Rectangle);
        rectangleDomStub = document.createElement("div");
        rectangleMock.should_receive("node").and_return(rectangleDomStub);        
        
        squigle.Canvas.prototype._canvasDependancy = adaptorCanvasMock; //Dependancy injection
        canvas = new squigle.Canvas(sizeMock);
        canvas.append(rectangleMock);
	},
	'Given squigle is available as a namespace': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And an instance of canvas is available': function(){
        value_of(typeof canvas).should_be('object');  
    },
    'And a shape has already been passed to append': function(){
        value_of(canvasDomStub.childNodes.length).should_be(1);
    },    
	'When a shape object is passed to remove then the shapes dom object will be returned': function() {       
        value_of( canvas.remove(rectangleMock)).should_be(rectangleDomStub);
	}
});

/**
    As a squigle user
    I want I want to have a fill class
    So that I have a uniform way to store fill values
 */
describe('Scenario 8: User creates a new fill object', {
	'before_each': function() {
        fill = new squigle.Fill("#FF0000", 50);
	},
	'Given squigle is available as a namespace': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And an instance of fill is available': function(){
        value_of(typeof fill).should_be('object');  
    },
	'When color is called "#FF0000" will be returned': function() {
        value_of(fill.color()).should_be("#FF0000");
	},
	'When opacity is called 50 will be returned': function() {
        value_of(fill.opacity()).should_be(50);
	}
});

/**
    As a squigle user
    I want I want to have a stroke class
    So that I have a uniform way to store stroke values
 */
describe('Scenario 9: User creates a new stroke object', {
	'before_each': function() {
        stroke = new squigle.Stroke("#FF0000", 50, 2, 'round', 'round');
	},
	'Given squigle is available as a namespace': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And an instance of fill is available': function(){
        value_of(typeof stroke).should_be('object');  
    },
	'When color is called "#FF0000" will be returned': function() {
        value_of(stroke.color()).should_be("#FF0000");
	},
	'When opacity is called 50 will be returned': function() {
        value_of(stroke.opacity()).should_be(50);
	},
	'When size is called 2 will be returned': function() {
        value_of(stroke.size()).should_be(2);
	},
	'When endcap is called "round" will be returned': function() {
        value_of(stroke.endcap()).should_be("round");
	},
	'When joincap is called "round" will be returned': function() {
        value_of(stroke.linejoin()).should_be("round");
	}
});

/**
    As a squigle user
    I want I want to have a path class
    So that I can easily draw custom shapes
 */
describe('Scenario 10: User creates a new path object', {
	'before_each': function() {      
        pathDomStub = document.createElement("div");
        
        var adapterPathMock = amok.mock(squigle.svgAdapter.Path);
        adapterPathMock.should_receive("node").and_return(pathDomStub);
        
        squigle.Path.prototype._pathDependancy = adapterPathMock; //Dependancy injection
        
        path = new squigle.Path(
            "M 10,100 C 10,10 100,10 100,100"    
        );
	},
	'Given squigle is available as a namespace': function() {
        value_of(typeof squigle).should_be('object');
	},
    'And an instance of Path is available': function(){
        value_of(typeof path).should_be('object');  
    },
	'When I call node() I will be returned my mock path dom object': function() {
        value_of(path.node()).should_be(pathDomStub);
	},
	'When I call moveTo() I will be returned the path object': function() {
        value_of(path.moveTo()).should_be(path);
	}
});

// ]]>

</script>
</head>
<body>
	<div style="display:none;"><p>A</p><p>B</p></div>
</body>
</html>
